<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
      <el-breadcrumb-item :to="{ path: '/' }">后台管理</el-breadcrumb-item>
      <el-breadcrumb-item>待收货订单管理</el-breadcrumb-item>
    </el-breadcrumb>



    <el-divider></el-divider>

    <el-table
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column prop="id" label="订单编号" width="150px" align="center"></el-table-column>
      <el-table-column prop="uphone" label="购买用户" width="150" align="center"></el-table-column>
      <el-table-column prop="money" label="金额" width="150" align="center"></el-table-column>
      <el-table-column prop="detailed" label="收货地址" width="250" align="center"></el-table-column>
<!--      <el-table-column prop="addressId" label="收货地址编号" width="150" align="center"></el-table-column>-->
      <el-table-column prop="name" label="收货人" width="150" align="center"></el-table-column>
      <el-table-column prop="phone" label="联系电话" width="150" align="center"></el-table-column>

      <el-table-column prop="state"label="是否发货" width="80" align="center">
        <template slot-scope="scope">
          <el-switch
              v-model="scope.row.state"
              @change="changState(scope.row)"
              :active-value="2"
              :inactive-value="1"
              active-color="#13ce66"
              inactive-color="#ff4949">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column prop="state"label="是否收货" width="80" align="center">
        <template slot-scope="scope">
          <el-switch
              v-model="scope.row.state"
              @change="changState(scope.row)"
              :active-value="3"
              :inactive-value="2"
              active-color="#13ce66"
              inactive-color="#ff4949">
          </el-switch>
        </template>
      </el-table-column>

      <el-table-column prop="createTime" label="创建时间" width="200" align="center"></el-table-column>
      <el-table-column prop="paymentTime" label="支付时间" width="200" align="center"></el-table-column>
      <el-table-column prop="sendTime" label="发货时间" width="200" align="center"></el-table-column>

      <el-table-column label="操作" width="220" align="center">
        <template slot-scope="scope">
          <!--          <el-button type="primary" icon="el-icon-edit" circle size="mini" @click="handleEdit(scope.row)"></el-button>-->
          <el-button type="info"  round size="mini" @click="selectGoods(scope.row)">查看订单对应的商品</el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>
<script>
import axios from "axios";

export default {
  data() {
    return {
      tableData: [],
      pack:{id:1,name:11},
      select1:{},
      pack1:{name:11},
      ruleForm: {

      },

    }
  },
  methods:{
    changState(goods){
      let stateArr=["未支付", "支付未发货","已支付已发货","发货未收货"];
      let url = 'http://localhost:8080/adminorders/state/' + goods.id;
      console.log(stateArr[goods.state])
       if(goods.state==1){
        console.log('将修改为已支付/代发货订单');
        url += '/pay';
      }else if(goods.state==3) {
        console.log('将修改为收货订单');
        url += '/receipt';
      }
      console.log('url = ' + url);
      this.axios.post(url).then((response) => {
        let responseBody = response.data;
        if (responseBody.state == 20000) {
          let message = '将订单【' + goods.id + '】的状态改为【' + stateArr[goods.state] + '】成功！';
          this.$message({
            message: message,
            type: 'success'
          });
          this.loadGoodsList();
        } else {
          this.$message.error(responseBody.message);
        }
        if (responseBody.state == 40400) {
          this.loadGoodsList();
        }
      });
    },
    selectGoods(row){
      let id=row.id;
      console.log("id=",id)
      localStorage.setItem("id",id);
      this.$router.push('/orders1-1');
    },
    loadGoodsList(){
      console.log('packlist')
      let url='http://localhost:8080/adminorders/deliverList';
      console.log('url='+url);
      this.axios.get(url).then((response)=>{
        let responseBody=response.data;
        this.tableData=responseBody.data;
      })
    }
  },
  mounted() {//挂载
    console.log('mounted')
    this.loadGoodsList();
  }

}
</script>